/*
 * $Id$
 *
 * Copyright 2006- Revolution Health Group.  All rights reserved.
 *
 * This software is the confidential and proprietary information
 * of Revolution Health Group.  (Confidential Information).
 * You shall not disclose such Confidential Information and shall
 * use it only in accordance with the terms of the license 
 * agreement you entered into with Revolution Health Group.
 *
 */
package org.javason.jsonrpc;

import java.util.List;

import org.javason.jsonrpc.description.Param;
import org.javason.jsonrpc.description.Proc;
import org.javason.jsonrpc.description.Service;

@Service (id="urn:TestService:1.0", name="TestService", version="1.0.0.1",
      summary="Test JSON service",
      help="http://www.revolutionhealth.com",
      address="http://www.revolutionhealth.com/TestService")
public class JsonRpcWebApp {
	
    public static class ResultType {
        public String result1;
        public int result2;
        
        public String getResult1() {
            return result1;
        }
        
        public void setResult1(String result1) {
            this.result1 = result1;
        }
        
        public int getResult2() {
            return result2;
        }
        
        public void setResult2(int result2) {
            this.result2 = result2;
        }
    }
    
    public static class ParamType {
        public String value1;
        public int value2;
        public List<Address> addresses;
        public int age;
        // currently int[] doesn't work
        public List<Integer> intvalues;
        
        public int getAge() {
            return age;
        }

        public void setAge(int age) {
            this.age = age;
        }

        public List<Integer> getIntvalues() {
            return intvalues;
        }
        
        public void setIntvalues(List<Integer> intvalues) {
            this.intvalues = intvalues;
        }

        public List<Address> getAddresses() {
            return addresses;
        }

        
        public void setAddresses(List<Address> addresses) {
            this.addresses = addresses;
        }

        public String getValue1() {
            return value1;
        }
        
        public void setValue1(String value1) {
            this.value1 = value1;
        }
        
        public int getValue2() {
            return value2;
        }
        
        public void setValue2(int value2) {
            this.value2 = value2;
        }
    }
    
    public static class Address {
        public String city;
        public int zip;
        
        public String getCity() {
            return city;
        }
        
        public void setCity(String city) {
            this.city = city;
        }
        
        public int getZip() {
            return zip;
        }
        
        public void setZip(int zip) {
            this.zip = zip;
        }
        
    }
    
    @Proc (name="method1", 
           summary="test method1", 
           help="http://www.revolutionhealth.com")
    public ResultType method1(@Param(name="input") ParamType input, @Param(name="another_input") Address addr, @Param(name="another_int") int value3) {
        ResultType result = new ResultType();
        result.result1 = "you entered text " + input.value1 + " " + addr.city + " ";
        if (input.addresses != null) {
        for (int i = 0; i < input.addresses.size(); i++) {
            result.result1 += input.addresses.get(i).city;
        }
        }
        result.result2 = input.age + input.value2 + addr.zip;
        if (input.addresses != null) {        
        for (int i = 0; i < input.addresses.size(); i++) {        
            result.result2 += input.addresses.get(i).zip;
        }
        }
        if (input.intvalues != null) {
        for (int i = 0; i < input.intvalues.size(); i++) {
            result.result2 += input.intvalues.get(i);
        }
        }
        return result;
    }
    
    public String method2(@Param(name="input") String param1, @Param(name="number") int param2) {
        return "you entered " + param1 + " " + param2;
    }
    
    public String method3(String input) {
        return "hello " + input;
    }
    
}
